package com.woniu.controller;

import com.woniu.common.CommonResult;
import com.woniu.entity.UsedProductType;
import com.woniu.service.UsedProductTypeService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.jws.WebParam;

/**
 * 商品类型表(UsedProductType)表控制层
 *
 * @author makejava
 * @since 2020-03-23 09:48:23
 */
@RestController
@RequestMapping("/usedProductType")
public class UsedProductTypeController {

    @Resource
    private UsedProductTypeService usedProductTypeService;

    /**
     * 功能描述: 根据用户选择的商品类别，查询数据库中商品类型名称
     * @Param: [typeId]
     * @Return: com.woniu.common.CommonResult
     * @Author: yanghan
     * @Date: 2020/3/25 15:28
     */
    @GetMapping("/findNameById/{typeId}")
    public @ResponseBody CommonResult findNameById(@PathVariable("typeId")Integer typeId){
        try {
            String typeName = usedProductTypeService.findNameById(typeId);
            return CommonResult.success("加载成功",typeName);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("数据查询失败");
        }
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public UsedProductType selectOne(Integer id) {
        return this.usedProductTypeService.queryById(id);
    }

}